package 试题和试卷;

import GUI.questionWindow;
import 数据库和网络.myDatebase;
import GUI.browzeFillingBlankWindow;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

public class fillingblankQuestionBaseItem extends questionBaseItem{

    public fillingblankQuestionBaseItem(){}

    public fillingblankQuestionBaseItem(int n, question currentquestion){
        super(n,currentquestion);
        detailButton.addActionListener(new detailListener());
        doButton.addActionListener(new deleteListener());

    }
    public class deleteListener implements ActionListener{
        @Override
        public void actionPerformed(ActionEvent e){
            myDatebase questionbase=new myDatebase("questioncollection");
            String sql="delete  from questioncollection.fillingblank_question where questionTitle='"+currentquestion.getTitle()+"'";
            try {
                questionbase.statement.execute(sql);

            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
            questionWindow.mainPanel.removeAll();
            questionWindow.mainPanel.updateUI();
        }

    }


    public class detailListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e){
            myDatebase questionbase=new myDatebase("questioncollection");
            String sql="select * from questioncollection.fillingblank_question where questionTitle="+currentquestion.getTitle()+"";
            try {
                questionbase.statement.execute(sql);
                questionbase.resultSet=questionbase.statement.executeQuery(sql);
                while (questionbase.resultSet.next()){
                    currentquestion.setText(questionbase.resultSet.getString("questiontext"));
                    currentquestion.setDifficulty(questionbase.resultSet.getDouble("questionDifficulties"));
                    currentquestion.setFullScore(questionbase.resultSet.getInt("fullScore"));
                    currentquestion.setAnswer(questionbase.resultSet.getString("answer"));
                }

            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
            browzeFillingBlankWindow fillingBlankWindow=new browzeFillingBlankWindow(currentquestion);
            fillingBlankWindow.questionContent.setText(currentquestion.getText());
            fillingBlankWindow.answerContent.setText(currentquestion.getAnswer());
            fillingBlankWindow.title.setText(currentquestion.getTitle());
            fillingBlankWindow.difficulty.setText(""+currentquestion.getDifficulty());
            fillingBlankWindow.score.setText(""+currentquestion.getFullScore());
            fillingBlankWindow.mainPanel.updateUI();
        }
    }
}
